package com.example.user_service.user_contorller.FDao;

import com.example.user_service.vo.AddressVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AddressMapper {

    @Select("select * from address where user_id=#{user_id} and status=#{status}")
    @Results(
            {
                    @Result(property = "addressid", column = "addressid"),
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "addressname", column = "addressname"),
                    @Result(property = "addressphone", column = "addressphone"),
                    @Result(property = "addresscode", column = "addresscode"),
                    @Result(property = "province", column = "province"),
                    @Result(property = "city", column = "city"),
                    @Result(property = "area", column = "area"),
                    @Result(property = "town", column = "town"),
                    @Result(property = "addressdetailed", column = "addressdetailed"),
                    @Result(property = "status", column = "status"),

            }

    )
    List<AddressVO> selectmyaddress(int user_id,int status);

    @Select("select * from address where addressid=#{addressid}")
    @Results(
            {
                    @Result(property = "addressid", column = "addressid"),
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "addressname", column = "addressname"),
                    @Result(property = "addressphone", column = "addressphone"),
                    @Result(property = "addresscode", column = "addresscode"),
                    @Result(property = "province", column = "province"),
                    @Result(property = "city", column = "city"),
                    @Result(property = "area", column = "area"),
                    @Result(property = "town", column = "town"),
                    @Result(property = "addressdetailed", column = "addressdetailed"),
                    @Result(property = "status", column = "status"),

            }

    )
    AddressVO selectaddressbyid(int addressid);

    @Insert("INSERT INTO address (user_id,addressname,addressphone,addresscode,province,city,area,town,addressdetailed,status) VALUES (#{user_id},#{addressname},#{addressphone},#{addresscode},#{province},#{city},#{area},#{town},#{addressdetailed},#{status});")
    int addaddress(AddressVO addressVO);

    @Update(" UPDATE address SET addressname=#{addressname},addressphone=#{addressphone},addresscode=#{addresscode},province=#{province},city=#{city},area=#{area},addressdetailed=#{addressdetailed},status=#{status} WHERE addressid = #{addressid} ")
    int updateaddress(AddressVO addressVO);

    @Update(" UPDATE address SET status = 0  WHERE user_id = #{user_id} ")
    void cleanstatus(int user_id);

    @Update(" UPDATE address SET status = 1  WHERE addressid=#{addressid} and user_id = #{user_id} ")
    int changedefault(int addressid,int user_id);

    @Delete("DELETE FROM address WHERE addressid = #{addressid} and user_id = #{user_id} ")
    int deleltadd(int addressid, int user_id);



}
